#include "thread.hpp"
#include <unistd.h>
using namespace std;
int count = 1000;
pthread_mutex_t _mutex = PTHREAD_MUTEX_INITIALIZER;
void *start_coutine(void *arg)
{
    while (1)
    {
        pthread_mutex_lock(&_mutex);
        if (count > 0)
        {
            usleep(500);
            --count;
            cout << pthread_self() << " -> " << count << endl;
            pthread_mutex_unlock(&_mutex);
        }
        else
        {
            pthread_mutex_unlock(&_mutex);
            break;
        }
        usleep(500);
    }
    return nullptr;
}
int main()
{
    pthread_t t1, t2;
    pthread_create(&t1, nullptr, start_coutine, nullptr);
    pthread_create(&t2, nullptr, start_coutine, nullptr);

    pthread_join(t1, nullptr);
    pthread_join(t2, nullptr);
    return 0;
}
